import json

import requests
import urllib.parse
import execjs
import time

# 获取当前时间的时间戳（秒）
current_time_seconds = time.time()

# 转换为毫秒
current_time_milliseconds = int(current_time_seconds * 1000)
params = {
    'appId': '5053',
    't': current_time_milliseconds,
    'cityCode': '520100',
    'pageIndex': '7',
    'pageSize': '12',
    'keyword': '日语',
    'order': '0',
}
eee={
    "cityCode": params['cityCode'],
    "pageIndex": params['pageIndex'],
    "pageSize": params['pageSize'],
    "keyword": urllib.parse.quote(params['keyword']),
    "order": params['order']
}

with open('./新东方.js', 'r', encoding='utf-8') as js_file:
    js_code = js_file.read()
js_compile = execjs.compile(js_code).call('ot',eee)

params=js_compile['params']
sign=js_compile['sign']
headers = {
    'accept': '*/*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'content-type': 'application/json',
    'origin': 'https://souke.xdf.cn',
    'priority': 'u=1, i',
    'referer': 'https://souke.xdf.cn/search?cityCode=520100&categoryCode=53&kw=%E7%A7%8B%E5%AD%A3',
    'sec-ch-ua': '"Chromium";v="128", "Not;A=Brand";v="24", "Microsoft Edge";v="128"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-site',
    'sign': sign,
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0',
}


response = requests.get('https://dsapi.xdf.cn/product/v2/class/search', params=params, headers=headers).json()
print(json.dumps(response, ensure_ascii=False, indent=4))